package com.example.young.peopleaccommodationms;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class SecondActicity extends BaseActivity implements View.OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //requeseWindow 必须放在oncreate前
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second_acticity);

        Log.d("SecondActivity", this.toString());

        Button button = (Button) findViewById(R.id.second_activity_btn);
        button.setOnClickListener(this);

//        Intent intent = getIntent();
//        String data = intent.getStringExtra("extra_data");
//        Log.d("SecondActivity", data);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.second_activity_btn:
//                有返回值的方式
//                Intent intent = new Intent();
//                intent.putExtra("data_return", "Hello FirstAc");
//                //setResult向上一个活动传递结果和intent
//                setResult(RESULT_OK, intent);
//                //销毁当前ac
//                finish();
                Intent intent = new Intent(SecondActicity.this, ThirdActivity.class);
                startActivity(intent);
        }
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra("data_return", "Hello FirstAc");
        //setResult向上一个活动传递结果和intent
        setResult(RESULT_OK, intent);
        //销毁当前ac
        finish();
    }

//    @Override
//    protected void onSaveInstanceState(Bundle outState) {
//        super.onSaveInstanceState(outState);
//        String tempData = "Something you just typed";
//        outState.putString("data_key", tempData);
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("SecondActivity", "onDestory");
    }

    public static void actionStart(Context context, String data1, String data2) {
        Intent intent = new Intent(context, SecondActicity.class);
        intent.putExtra("param1", data1);
        intent.putExtra("param2", data2);
        context.startActivity(intent);

    }
}
